//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "FdmExtendedOrnsteinUhlenbackOp.h"
using namespace Cephei::QL::Experimental::Finitedifferences;
#include <gen/QL/Math/Array.h>
#include <gen/QL/Methods/Finitedifferences/Meshers/FdmMesher.h>
#include <gen/QL/Experimental/Processes/ExtendedOrnsteinUhlenbeckProcess.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL::Methods::Finitedifferences::Meshers;
using namespace Cephei::QL::Experimental::Processes;
using namespace Cephei::QL::Termstructures;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFdmExtendedOrnsteinUhlenbackOp = NULL;
#endif
	_ppFdmExtendedOrnsteinUhlenbackOp = &childNative;
    
}
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (QuantLib::FdmExtendedOrnsteinUhlenbackOp& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phFdmExtendedOrnsteinUhlenbackOp = NULL;
#endif
	_ppFdmExtendedOrnsteinUhlenbackOp = new boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp> (&childNative);
    
    _FdmExtendedOrnsteinUhlenbackOpOwner = owner;
    
}

Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (CFdmExtendedOrnsteinUhlenbackOp^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFdmExtendedOrnsteinUhlenbackOp = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFdmExtendedOrnsteinUhlenbackOp = new boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp> (copy->GetShared());
        
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFdmExtendedOrnsteinUhlenbackOp = NULL;
#endif
	if (!t->IsSubclassOf(CFdmExtendedOrnsteinUhlenbackOp::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (QuantLib::Handle<QuantLib::FdmExtendedOrnsteinUhlenbackOp>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phFdmExtendedOrnsteinUhlenbackOp = &childNative;
	_ppFdmExtendedOrnsteinUhlenbackOp = &static_cast<boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp>>(childNative.currentLink());
    
    _FdmExtendedOrnsteinUhlenbackOpOwner = owner;
}
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (QuantLib::Handle<QuantLib::FdmExtendedOrnsteinUhlenbackOp> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phFdmExtendedOrnsteinUhlenbackOp = &childNative;
	_ppFdmExtendedOrnsteinUhlenbackOp = &static_cast<boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::CFdmExtendedOrnsteinUhlenbackOp (QuantLib::FdmExtendedOrnsteinUhlenbackOp childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phFdmExtendedOrnsteinUhlenbackOp = NULL;
#endif
	_ppFdmExtendedOrnsteinUhlenbackOp = new boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp> (new QuantLib::FdmExtendedOrnsteinUhlenbackOp (childNative));
    
}
#endif

Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::~CFdmExtendedOrnsteinUhlenbackOp ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppFdmExtendedOrnsteinUhlenbackOp != NULL)
    {
	    delete _ppFdmExtendedOrnsteinUhlenbackOp;
        _ppFdmExtendedOrnsteinUhlenbackOp = NULL;
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::!CFdmExtendedOrnsteinUhlenbackOp ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppFdmExtendedOrnsteinUhlenbackOp != NULL)
    {
	    delete _ppFdmExtendedOrnsteinUhlenbackOp;
    }
}
QuantLib::FdmExtendedOrnsteinUhlenbackOp& Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::GetReference ()
{
    if (_ppFdmExtendedOrnsteinUhlenbackOp == NULL) throw REFNEW NativeNullException ();
	return **_ppFdmExtendedOrnsteinUhlenbackOp;
}
boost::shared_ptr<QuantLib::FdmExtendedOrnsteinUhlenbackOp>& Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::GetShared ()
{
    if (_ppFdmExtendedOrnsteinUhlenbackOp == NULL) throw REFNEW NativeNullException ();
	return *_ppFdmExtendedOrnsteinUhlenbackOp;
}
QuantLib::FdmExtendedOrnsteinUhlenbackOp* Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::GetPointer ()
{
    if (_ppFdmExtendedOrnsteinUhlenbackOp == NULL) throw REFNEW NativeNullException ();
	return &**_ppFdmExtendedOrnsteinUhlenbackOp;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FdmExtendedOrnsteinUhlenbackOp>& Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::GetHandle ()
{
	if (_phFdmExtendedOrnsteinUhlenbackOp == NULL)
	{
		_phFdmExtendedOrnsteinUhlenbackOp = new Handle<QuantLib::FdmExtendedOrnsteinUhlenbackOp> (*_ppFdmExtendedOrnsteinUhlenbackOp);
	}
	return *_phFdmExtendedOrnsteinUhlenbackOp;
}
#endif
bool Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::HasNative () 
{
	return (_ppFdmExtendedOrnsteinUhlenbackOp != NULL);
}

Cephei::QL::Experimental::Finitedifferences::IFdmExtendedOrnsteinUhlenbackOp^ Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::SetTime (Double t1, Double t2)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Time _t1 = (QuantLib::Time)ValueHelper::Convert (t1); //a
        QuantLib::Time _t2 = (QuantLib::Time)ValueHelper::Convert (t2); //a
    	(*_ppFdmExtendedOrnsteinUhlenbackOp)->setTime ( _t1,  _t2 );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Experimental::Finitedifferences::CFdmExtendedOrnsteinUhlenbackOp::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppFdmExtendedOrnsteinUhlenbackOp)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

